// pages/consult/zhengzhangjing/zhengzhangjing.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    consultDetial:{},
    losthost:'',
    teacherId:1,
    url:'',
    courseDetail:{},
    ArticleDetail:{},
    imageList:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //获取全局的url赋值给当前页面的url变量
    this.setData({
      url: app.globalData.URL,
      losthost: app.globalData.losthost,
      teacherId:wx.getStorageSync('consultDetial').id
    })
    let that = this;
    // console.log("teacherid:",that.data.teacherId)
    // console.log("url", that.data.url)
    // console.log(that.data.url + '/vCourse/getCourseByPage?teacherId='+that.data.teacherId)
        // 从缓存中获取咨询师详情
        const detail = wx.getStorageSync('consultDetial');
        // console.log("detail:=>",detail)
        if (detail) {
          this.setData({
            consultDetial: detail
          });
        }
        this.getcourseDetail();
        this.getAtricleDetail();
  },
  //查看证书
  lookbook(){
    console.log("查看证书")
    const that = this;
    const imageList = this.data.consultDetial.consultcertificate
    console.log("==",imageList)
    const imageUrls = imageList.map(item=>item.certificateimage)
    wx.previewImage({
      current: that.data.losthost+imageUrls[0], // 当前显示的图片链接
      urls: imageUrls,       // 所有图片链接的数组
      success() {
        console.log("图片预览地址：",that.data.losthost+imageUrls[0])
        console.log("图片预览成功");
      },
      fail(err) {
        console.error("预览失败:", err.errMsg);
      }
    });
  },
  //获取课程信息
  getcourseDetail(){
    let that=this;
    //调用接口
    wx.request({
      url: that.data.url + '/vCourse/getCourseByPage?pageNum=1&pageSize=3&teacherId=' + that.data.teacherId,
      success(resp) {
        // console.log("consultList==>", resp.data.data.list)
        that.setData({
          courseDetail: resp.data.data.list
        })
        // console.log("==", that.data.courseDetail)
      }
    })
  },
  //获取咨询师文章信息
  getAtricleDetail(){
    let that=this;
    console.log("请求地址：",that.data.url+'article?pageNum=1&pageSize=3&consultId'+that.data.teacherId)
    wx.request({
      url: that.data.url+'article?pageNum=1&pageSize=3&consultId'+that.data.teacherId,
      success(resp){
        console.log("AtricleList==>", resp.data.data.list)
        that.setData({
          ArticleDetail: resp.data.data.list
        })
        console.log("==", that.data.ArticleDetail)
      }
    })
  },
  //去发布课程页面
  goCourse(){
    console.log("去课程页面")
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})